<script setup lang="ts">
import Tips from '@/components/tips/Tips.vue'
import { onMounted, ref } from 'vue'
import AppMain from './views/appMain/Main.vue'
import Update from './views/update/Update.vue'
import { useEnv } from './store/useEnv'
import { $postMessage } from '@/utils/ipcRenderer'

const env = useEnv()
onMounted(env.checkIsIpv6)
const loadingFinish = ref(false) // 是否更新完毕(pc端)

if (env.IS_ELECTRON) {
  const { ipcRenderer } = require('electron')
  ipcRenderer.on('update-finish', () => (loadingFinish.value = true))

  const isDevelopment = process.env.NODE_ENV !== 'production'
  // 开发模式会跳过检查更新，此处为了模拟加载情况
  if (isDevelopment) {
    $postMessage(({ mainWin }) => {
      mainWin.webContents.send('download-progress', 100)
      setTimeout(() => mainWin.webContents.send('update-finish'), 1000)
    })
  }
} else {
  loadingFinish.value = true
}
</script>

<template>
  <Tips />
  <Transition enter-from-class="opacity-0" leave-to-class="opacity-0">
    <Component :is="loadingFinish ? AppMain : Update" />
  </Transition>
</template>

<style>
@import url('./assets/css/global.css');
</style>
